﻿@using VocaDb.Model.Domain.Security
@using VocaDb.Web.Helpers
@using Res = ViewRes.Discussion.IndexStrings
@inherits VocaDb.Web.Code.VocaDbPage

<div data-bind="visible: selectedFolder() !== null && selectedTopic() === null" class="discussion-folder">
	
	<ul data-bind="foreach: folders" class="nav nav-pills folder-list">
		<li data-bind="css: { active: $data == $parent.selectedFolder() }">
			<a href="{{'/discussion/folders/' + id}}" title="{{description}}">
				{{name}}
			</a>
		</li>
	</ul>
	
	<p data-bind="visible: selectedFolder() && selectedFolder().description" class="folder-description">
		{{selectedFolder() ? selectedFolder().description : ''}}
	</p>

	@if (UserContext.HasPermission(PermissionToken.CreateComments)) {
		<button data-bind="visible: !showCreateNewTopic(), click: function() { showCreateNewTopic(true); }" class="btn create-topic">
			<i class="icon-comment"></i>
			@Res.WriteNewPost
		</button>

		<form data-bind="visible: showCreateNewTopic, submit: createNewTopic" class="well well-transparent">
			<div data-bind="with: newTopic">
				@{ Html.RenderPartial("Partials/_EditTopic"); }
			</div>
			<button type="submit" class="btn btn-primary">@Res.DoPost</button>
		</form>
	}

	<div data-bind="with: paging">
		@KnockoutHelpers.ServerSidePaging()
	</div>

	<table class="table">
		<thead>
			<tr>
				<th>@Res.Topic</th>
				<th>@Res.Author</th>
				<th class="hidden-phone">@Res.Comments</th>
				<th>@Res.Created</th>
				<th>@Res.LastComment</th>
			</tr>
		</thead>
		<tbody data-bind="foreach: topics" class="discussion-topics">
			<tr data-bind="css: { active: $data == $parent.selectedTopic() }, click: $parent.selectTopic">
				<td>					
					<span>{{name}}</span>
				</td>
				<td>
					<span data-bind="with: author">
						@UserHelpers.ProfileIconKnockout(VocaDb.Model.Domain.Images.ImageSize.TinyThumb, size: 18)
						<span>{{name}}</span>
					</span>
				</td>
				<td class="hidden-phone">
					<span>{{commentCount}}</span>
				</td>
				<td>
					<span>{{created | formatDate:'lll'}}</span>
				</td>
				<td>
					<span data-bind="if: $data.lastComment">
						{{lastComment.created | formatDate:'lll'}} by {{lastComment.authorName}}
					</span>
				</td>
			</tr>
		</tbody>
	</table>
	
	<div data-bind="with: paging">
		@KnockoutHelpers.ServerSidePaging()
	</div>

</div>

